package dcmqueryclient;

import at.dcmspl.*;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;


/**
 *
 * @author Hannes Stornig, Gosch Daniel
 */
public class Main {
    @EJB
    private static DcmQueueServiceRemote dcmQueueService;


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### STARTING CLIENT........");
                
        /*
        DicomReader dr = new DicomReader();
        DicomObject homer = dr.readDcm("homer.dcm");
        DicomObject x = dr.readDcm("multicolorLEI.dcm");
        //Logger.getLogger(DcmQueueServiceRemote.class.getName()).log(Level.INFO, "Dicomfile: {0}",x);
        Logger.getLogger(DcmQueueServiceRemote.class.getName()).log(Level.INFO, "Dicomfile Homer: {0}",homer);
        //DicomWriter dw = new DicomWriter();
        //dw.writeDicomFile(x,"newFile.dcm");
        */
        
        //EJB Methoden
        dcmQueueService.createDcmQueue("ersteQueue");
        dcmQueueService.createDcmQueue("zweiteQueue");
        dcmQueueService.addDcmFile("zweiteQueue", "ErstesDcmFile");
        dcmQueueService.addDcmFile("zweiteQueue", "ZweitesDcmFile");
        dcmQueueService.addDcmFile("zweiteQueue", "DrittesDcmFile");
        dcmQueueService.addDcmFile("zweiteQueue", "ViertesDcmFile");
        
        //PEEK
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "Peek:");
        DcmFile peek = dcmQueueService.peekDcmFile(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### Gepeektes Dicom File {0}",peek);
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### Remove {0}", peek);
        dcmQueueService.removeDcmFile(dcmQueueService.findDcmQueueByName("zweiteQueue"), peek);
       
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### GetAllDicomFiles {0}........",dcmQueueService.findDcmQueueByName("zweiteQueue").getAllDcmFiles().toString());
        
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "##### MOVE TO HEAD");
        dcmQueueService.movetoHead(dcmQueueService.findDcmQueueByName("zweiteQueue"), 1);
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### GetAllDicomFiles after move {0}........",dcmQueueService.findDcmQueueByName("zweiteQueue").getAllDcmFiles().toString());    
        
        //POOL
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### POOL");
        DcmFile pool = dcmQueueService.poolDcmFile(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### Gepooltes Dicom File {0}",pool);
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### DcmFileList {0}........",dcmQueueService.findDcmQueueByName("zweiteQueue").getAllDcmFiles().toString());
        
        //Aufräumen
        //dcmQueueService.remove(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        //dcmQueueService.remove(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        dcmQueueService.remove(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        dcmQueueService.remove(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        Logger.getLogger(Main.class.getName()).log(Level.INFO, "### GetAllDicomFiles {0}........",dcmQueueService.findDcmQueueByName("zweiteQueue").getAllDcmFiles().toString());    
        
        
        dcmQueueService.removeDcmQueue(dcmQueueService.findDcmQueueByName("ersteQueue"));
        dcmQueueService.removeDcmQueue(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        
        //dcmQueueService.poolDcmFile(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        //Logger.getLogger(Main.class.getName()).log(Level.INFO, "### DcmFileList {0}........",dcmQueueService.findDcmQueueByName("zweiteQueue").getAllDcmFiles().toString());
        //dcmQueueService.poolDcmFile(dcmQueueService.findDcmQueueByName("zweiteQueue"));
        //Logger.getLogger(Main.class.getName()).log(Level.INFO, "### DcmFileList {0}........",dcmQueueService.findDcmQueueByName("zweiteQueue").getAllDcmFiles().toString());
    }
}
